import { SDF } from './SDF';

const { ccclass, menu, property } = cc._decorator;

@ccclass
export class TestSDF extends cc.Component {
    @property(cc.Node)
    renderNode: cc.Node = null;

    protected _sdf: SDF;

    onLoad() {}

    start() {
        this._sdf = new SDF();
        this.NextImage();
    }

    protected NextImage() {
        let sz = this.renderNode.getComponent(cc.Sprite).spriteFrame.getOriginalSize();

        // let sdfRadius = 60;
        let sdfRadius = Math.max(60, sz.height / 3);
        let cutoff = 0.5;
        let texture = this._sdf.RenderToMemory(
            this.renderNode,
            null,
            this.renderNode,
            sdfRadius * (1 - cutoff)
        );
        let result = this._sdf.RenderSDF(texture, sdfRadius, cutoff);

        let sprite = this.renderNode.getComponent(cc.Sprite);
        sprite.spriteFrame = new cc.SpriteFrame(result.texture);
    }
}
